//
//  HelpGeneralVC.m
//  eyr
//
//  Created by Tor Gjøsæter on 6/20/12.
//  Copyright (c) 2012 University of Bergen. All rights reserved.
//

#import "HelpGeneralVC.h"
#import <QuartzCore/QuartzCore.h>


@interface HelpGeneralVC ()

@end

@implementation HelpGeneralVC


@synthesize connectorImage;
@synthesize cableImage;
@synthesize stoneImage;
@synthesize ipadImage;
@synthesize connectortop;
@synthesize ledImage;
@synthesize ladeStein;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.

    
    
    ipadImage.alpha = 0.0;
    connectorImage.alpha = 0.0;
    connectortop.alpha = 0.0;
    cableImage.alpha = 0.0;
    stoneImage.alpha = 0.0;
    ledImage.alpha = 0.0;
    
    ipadImage.layer.zPosition = 3;
    connectorImage.layer.zPosition = 0;
    cableImage.layer.zPosition = 1;
    connectortop.layer.zPosition = 2;
    stoneImage.layer.zPosition =2;
    
    [UIView 
            animateWithDuration:0.5
            delay:0.0
            options: UIViewAnimationOptionCurveEaseIn
            animations:^{
                         stoneImage.alpha = 1.0;
                        }
            completion:^(BOOL finished){
                                        [UIView 
                                         animateWithDuration:0.5
                                         delay: 0.0
                                         options:UIViewAnimationOptionCurveEaseOut
                                         animations:^{
                                                    cableImage.alpha = 1.0;
                                                    }
                                         completion:^(BOOL finished){
                                             [UIView 
                                              animateWithDuration:0.5
                                              delay: 0.0
                                              options:UIViewAnimationOptionCurveEaseOut
                                              animations:^{
                                                  connectorImage.alpha = 1.0;
                                                  connectortop.alpha = 1.0;
                                              }
                                              completion:^(BOOL finished){
                                                  [UIView 
                                                   animateWithDuration:0.5
                                                   delay: 0.0
                                                   options:UIViewAnimationOptionCurveEaseOut
                                                   animations:^{
                                                       ipadImage.alpha = 1.0;
                                                   }
                                                   completion:nil];
                                              }];
                                         }];
                                        }
     ];
    
    

    
    [self animateDevicesIn];
    [self animateLedBlinkIn];
    
       
    
}

-(void) animateLedBlinkIn{
    [UIView 
     animateWithDuration:2.0
     delay:0.0
     options: UIViewAnimationOptionCurveEaseIn
     animations:^{
         ledImage.alpha = 1.0;
         ladeStein.transform = CGAffineTransformMakeScale(1.0, 0.9);
     }
     completion:^(BOOL finished){
         [self animateLedBlinkOut];
     }
     ];
         
    
}

-(void) animateLedBlinkOut{
    [UIView 
     animateWithDuration:2.0
     delay:0.0
     options: UIViewAnimationOptionCurveEaseIn
     animations:^{
         ledImage.alpha = 0.0;
         ladeStein.transform = CGAffineTransformMakeScale(1.0, 1.0);
     }
     completion:^(BOOL finished){
                       [self animateLedBlinkIn];
                        }
     ];
    
}



-(void) animateDevicesIn
{
    [UIView 
     animateWithDuration:1.0
     delay:2.5
     options: UIViewAnimationOptionCurveEaseIn
     animations:^{
         connectorImage.frame = CGRectMake(connectorImage.frame.origin.x+12.0,connectorImage.frame.origin.y, connectorImage.frame.size.width, connectorImage.frame.size.height);
         connectortop.frame = CGRectMake(connectortop.frame.origin.x+12.0,connectortop.frame.origin.y, connectortop.frame.size.width, connectortop.frame.size.height);

     }
     completion:^(BOOL finished){
         [UIView 
          animateWithDuration:1.0
          delay: 0.0
          options:UIViewAnimationOptionCurveEaseOut
          animations:^{
              cableImage.frame = CGRectMake(cableImage.frame.origin.x+33.0,cableImage.frame.origin.y, cableImage.frame.size.width, cableImage.frame.size.height);
          }
          completion:^(BOOL finished){
              [UIView 
               animateWithDuration:1.0
               delay: 0.0
               options:UIViewAnimationOptionCurveEaseOut
               animations:^{
                   stoneImage.frame = CGRectMake(stoneImage.frame.origin.x+50.0,stoneImage.frame.origin.y, stoneImage.frame.size.width, stoneImage.frame.size.height);
               }
               completion:^(BOOL finished){
                   [UIView 
                    animateWithDuration:1.0
                    delay: 3.0
                    options:UIViewAnimationOptionCurveEaseOut
                    animations:^{
                        [self animateDevicesOut];
                    }
                    completion:nil];
               }];
          }];
     }
     ];
}

-(void) animateDevicesOut
{
    [UIView 
     animateWithDuration:1.0
     delay:5.5
     options: UIViewAnimationOptionCurveEaseIn
     animations:^{
         stoneImage.frame = CGRectMake(stoneImage.frame.origin.x-50.0,stoneImage.frame.origin.y, stoneImage.frame.size.width, stoneImage.frame.size.height);
     }
     completion:^(BOOL finished){
         [UIView 
          animateWithDuration:1.0
          delay: 0.0
          options:UIViewAnimationOptionCurveEaseOut
          animations:^{
              cableImage.frame = CGRectMake(cableImage.frame.origin.x-33.0,cableImage.frame.origin.y, cableImage.frame.size.width, cableImage.frame.size.height);
          }
          completion:^(BOOL finished){
              [UIView 
               animateWithDuration:1.0
               delay: 0.0
               options:UIViewAnimationOptionCurveEaseOut
               animations:^{
                   connectorImage.frame = CGRectMake(connectorImage.frame.origin.x-12.0,connectorImage.frame.origin.y, connectorImage.frame.size.width, connectorImage.frame.size.height);
                   connectortop.frame = CGRectMake(connectortop.frame.origin.x-12.0,connectortop.frame.origin.y, connectortop.frame.size.width, connectortop.frame.size.height);

                   
               }
               completion:^(BOOL finished){
                   [UIView 
                    animateWithDuration:1.0
                    delay: 3.0
                    options:UIViewAnimationOptionCurveEaseOut
                    animations:^{
                        [self animateDevicesIn];
                    }
                    completion:nil];
               }];
          }];
     }
     ];
}

- (void)viewDidUnload
{

    [self setConnectorImage:nil];
    [self setCableImage:nil];
    [self setStoneImage:nil];

    [self setIpadImage:nil];
    [self setConnectortop:nil];
    [self setLedImage:nil];
    [self setLadeStein:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


@end
